<?php
class Club_AdminClbkhachhangController extends Zendvn_Controller_Action{
	
	//Mang tham so nhan duoc khi mot Action chay
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	//Thong so phan trang
	protected $_paginator = array(
									'itemCountPerPage' => 15,
									'pageRange' => 10,
									'currentPage' => 1
									);
	protected $_namespace;
	
	//Url page
	protected $_page = '';
	
	public function init(){
		//Mang tham so nhan duoc khi mot Action chay
		$this->_arrParam = $this->_request->getParams();
	
		//Duong dan cua Controller
		$this->_currentController = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'];
	
		//Duong dan cua Action chinh
		$this->_actionMain = '/' . $this->_arrParam['module'] . '/'	. $this->_arrParam['controller'] . '/index';	
	
		//Luu cac du lieu filter vaof SESSION
		//Dat ten SESSION
		$this->_namespace = $this->_arrParam['module'] . '-' . $this->_arrParam['controller'];
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
		//Lay thong tin so phan tu tren mot trang
		if(isset($this->_arrParam['limitPage'])){
			$ssFilter->limitPage = $this->_request->getParam('limitPage');
			$this->_paginator['itemCountPerPage'] = $ssFilter->limitPage;
		}elseif(!empty($ssFilter->limitPage)){
			$this->_paginator['itemCountPerPage'] = $ssFilter->limitPage;
		}
		
		//Trang hien tai
		if(isset($this->_arrParam['page'])){
			$this->_paginator['currentPage'] = $this->_arrParam['page'];
			$this->_page = '/page/' . $this->_arrParam['page'];
		}
		
		//Truyen thong tin phan trang vao mang du lieu
		$this->_arrParam['paginator'] = $this->_paginator;
		
		//$ssFilter->unsetAll();
		if(empty($ssFilter->col)){
			$ssFilter->keywords = '';
			$ssFilter->col 		= 'a.id';
			$ssFilter->order 	= 'DESC';
			$ssFilter->id_clb	= 0;
			$ssFilter->status	= 0;
		}
		$this->_arrParam['ssFilter']['keywords'] 	= $ssFilter->keywords;
		$this->_arrParam['ssFilter']['col'] 		= $ssFilter->col;
		$this->_arrParam['ssFilter']['order'] 		= $ssFilter->order;
		$this->_arrParam['ssFilter']['id_clb'] 		= $ssFilter->id_clb;
		$this->_arrParam['ssFilter']['status'] 		= $ssFilter->status;

		//Truyen ra ngoai view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
	
		$siteConfig = Zend_Registry::get('siteConfig');
		$template_path = TEMPLATE_PATH . "/admin/" . $siteConfig['template']['admin'];
		$this->loadTemplate($template_path, 'template.ini', 'template');
	}

	public function indexAction(){
		$this->view->Title = 'Câu lạc bộ :: Danh sách thành viên';
		$this->view->headTitle($this->view->Title, true);
		
		$tblClbkhachhang = new Club_Model_Clbkhachhang();
		$this->view->Items = $tblClbkhachhang->listItem($this->_arrParam, array('task'=>'admin-list'));
		$this->view->slbClb = $tblClbkhachhang->itemInSelectbox($this->_arrParam);
		
		
		$totalItem = $tblClbkhachhang->countItem($this->_arrParam, array('task'=>'admin-list'));
		//echo $totalItem; die;
		$paginator = new Zendvn_Paginator();
		$this->view->paginator = $paginator->createPaginator($totalItem, $this->_paginator);
	}
	
	public function filterAction(){
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
		
		if($this->_arrParam['type'] == 'search'){
			if($this->_arrParam['key'] == 1){
				$ssFilter->keywords = trim($this->_arrParam['keywords']);
			}else{
				$ssFilter->keywords = '';
			}
		}
		
		if($this->_arrParam['type'] == 'id_clb'){
			$ssFilter->id_clb = $this->_arrParam['id_clb'];
		}
	
		if($this->_arrParam['type'] == 'status'){
			$ssFilter->status = $this->_arrParam['status'];
		}
		
		if($this->_arrParam['type'] == 'order'){
			$ssFilter->col = $this->_arrParam['col'];
			$ssFilter->order = $this->_arrParam['by'];
		}
	
		$this->_redirect($this->_actionMain);
	
		$this->_helper->viewRenderer->setNoRender();
	}
	

	public function infoAction(){
		$this->view->Title = 'Câu lạc bộ :: Xem thông tin';
		$this->view->headTitle($this->view->Title, true);
		$tblClb = new Club_Model_Clb();
		$this->view->Item = $tblClb->getItem($this->_arrParam,array('task'=>'admin-info'));
		
		$tblUser = new Default_Model_Users();
		$this->view->createdBy = $tblUser->getItem(array('id' => $this->view->Item['created_by']),array('task'=>'admin-info'));
		$this->view->modifiedBy = $tblUser->getItem(array('id' => $this->view->Item['modified_by']),array('task'=>'admin-info'));
		
	}
	
	
	public function addAction(){
		$id_kh=$this->_arrParam['id_kh'];
		//echo $id_kh;die;
		
		if($id_kh==null){
			$this->view->Title = 'Thu phi c câu lạc bộ :: Thêm mới';
			$this->view->headTitle($this->view->Title, true);
		
			$tblEvent = new Club_Model_Event();
			$this->view->slbClb = $tblEvent->itemInSelectbox($this->_arrParam);
			//$this->view->slbUser = $tblEvent->userInSelectbox($this->_arrParam);
			
			if($this->_request->isPost()){
					
				$validator = new Club_Form_ValidateEvent($this->_arrParam);
				if($validator->isError() == true){
					$this->view->messageError = $validator->getMessageError();
					$this->view->Item = $validator->getData();
				}else{
					$arrParam = $validator->getData();
					$tblEvent->saveItem($arrParam,array('task'=>'admin-add'));
					$this->_redirect($this->_actionMain);
				}
			}
		}else{

			$this->view->Title = 'Thu phí tham gia CLB';
			$this->view->headTitle($this->view->Title, true);
			$tblThuphi = new Club_Model_Clbkhachhang();
			$this->view->ItemUser = $tblThuphi->getUser($this->_arrParam);
			
			$this->view->slbClub = $tblThuphi->ClubInSelectbox($this->_arrParam);
			$this->view->slbUser = $tblThuphi->userInSelectbox($this->_arrParam);
			
			
			if($this->_request->isPost()){
				//var_dump($this->_arrParam);die;
				$validator = new Club_Form_ValidateClbkhachhang($this->_arrParam);
				if($validator->isError() == true){
					$this->view->messageError = $validator->getMessageError();
					$this->view->Item = $validator->getData();
				}else{
					$arrParam = $validator->getData();
					$tblThuphi->saveItem($arrParam,array('task'=>'admin-add'));
					$this->_redirect($this->_actionMain . $this->_page);
				}
			}
		}
	}
	
	
	public function editAction(){
		$this->view->Title = 'Event câu lạc bộ :: Sửa';
		$this->view->headTitle($this->view->Title, true);
		
		$tblEvent = new Club_Model_Event();
		$this->view->Item = $tblEvent->getItem($this->_arrParam,array('task'=>'admin-edit'));
		
		$this->view->slbClb = $tblEvent->itemInSelectbox($this->_arrParam);
		//$this->view->slbUser = $tblEvent->userInSelectbox($this->_arrParam);
		
		
		if($this->_request->isPost()){
			//var_dump($this->_arrParam);die;
			$validator = new Club_Form_ValidateEvent($this->_arrParam);
			if($validator->isError() == true){
				$this->view->messageError = $validator->getMessageError();
				$this->view->Item = $validator->getData();
			}else{
				$arrParam = $validator->getData();
				$tblEvent->saveItem($arrParam,array('task'=>'admin-edit'));
				$this->_redirect($this->_actionMain . $this->_page);
			}
		}
	}
	
	public function deleteAction(){
		$this->view->Title = 'Xóa thành viên câu lạc bộ :: Xóa';
		$this->view->headTitle($this->view->Title, true);
		if($this->_request->isPost()){
			if(($this->_arrParam['type'] == 'multi-delete') && ($this->_arrParam['task'] == 'ok')){
				$tblEvent = new Club_Model_Clbkhachhang();
				$tblEvent->deleteItem($this->_arrParam, array('task'=>'admin-delete-muti'));
				$this->_redirect($this->_actionMain . $this->_page);
			}else
				if(!empty($this->_arrParam['id'])){
				$tblEvent = new Club_Model_Clbkhachhang();
				$tblEvent->deleteItem($this->_arrParam, array('task'=>'admin-delete'));
				$this->_redirect($this->_actionMain . $this->_page);
			}
		}
	}
	
	public function statusAction(){
		$tblClb = new Club_AdminClbController();
		$tblClb->changeStatus($this->_arrParam);
		$this->_redirect($this->_actionMain . $this->_page);
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function sortAction(){
		if($this->_request->isPost()){
			$tblCustomer = new Customer_Model_Item();
			$tblCustomer->sortItem($this->_arrParam, array('task'=>'admin-sort'));
			$this->_redirect($this->_actionMain . $this->_page);
		}
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	
	

	public function excelAction(){
		
		$ssFilter = $this->_arrParam['ssFilter'];
		
		$tblClb = new Club_Model_Clbkhachhang();
		$this->view->Items = $listKhachhangclb = $tblClb->listItem($this->_arrParam, array('task'=>'admin-excel'));
		
		$info = new Zendvn_System_Info();
		$userInfo = $info->getMemberInfo();
		/* echo "<pre>";
		print_r($info->getMemberInfo());
		echo "</pre>"; */
		
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
	
		error_reporting(E_ALL);
		ini_set('display_errors', TRUE);
		ini_set('display_startup_errors', TRUE);
		date_default_timezone_set('Asia/Ho_Chi_Minh');
	
		if (PHP_SAPI == 'cli')
			die('This example should only be run from a Web Browser');
	
		/** Include PHPExcel */
		require_once SCRIPTS_PATH . '/phpexcel/PHPExcel.php';
	
		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();
	
		// Set document properties
		$objPHPExcel->getProperties()->setCreator($userInfo['user_name'])
		->setLastModifiedBy($userInfo['user_name'])
		->setTitle("Danh sach khach hang")
		->setSubject("Danh sach khach hang")
		->setDescription("Danh sach khach hang duoc xuat boi " . $userInfo['user_name'])
		->setKeywords($userInfo['user_name'])
		->setCategory($userInfo['user_name']);
	
		// Tiêu đề
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('B2', 'DANH SÁCH KHÁCH HÀNG')->mergeCells('B2:G2');
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setSize(20)->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLUE);
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS);
	
		// Fillter
		$start = 4;
		$objPHPExcel->setActiveSheetIndex(0)
			->setCellValue('B'.$start, 'Ngày xuất: '.@date('d/m/Y h:i:s'))->mergeCells('B'.$start.':C'.$start);
		$objPHPExcel->setActiveSheetIndex(0)
		->setCellValue('D'.$start, 'Bởi: '.$userInfo['user_name'])->mergeCells('D'.$start.':E'.$start);
		
// 		if($ssFilter['khoahoc_id'] > 0){
// 			$start++;
// 			$tblKhoahoc = new Club_Model_Clbkhachhang();
// 			$khoahoc = $tblKhoahoc->getItem(array('id' => $ssFilter['khoahoc_id']),array('task' => 'admin-info'));
// 			$objPHPExcel->setActiveSheetIndex(0)
// 			->setCellValue('B'.$start, 'Khóa học: '.$khoahoc['name'])->mergeCells('B'.$start.':E'.$start);
// 		}
		
// 		if($ssFilter['trungtam_id'] > 0){
// 			$start++;
// 			$tblTrungtam = new Club_Model_Clbkhachhang();
// 			$trungtam = $tblTrungtam->getItem(array('id' => $ssFilter['trungtam_id']),array('task' => 'admin-info'));
// 			$objPHPExcel->setActiveSheetIndex(0)
// 			->setCellValue('B'.$start, 'Cơ sở: '.$trungtam['name'])->mergeCells('B'.$start.':E'.$start);
// 		}
		
		
// 		if($ssFilter['nguontin_id'] > 0){
// 			$start++;
// 			$tblNguontin = new Club_Model_Clbkhachhang();
// 			$nguontin = $tblNguontin->getItem(array('id' => $ssFilter['nguontin_id']),array('task' => 'admin-info'));
// 			$objPHPExcel->setActiveSheetIndex(0)
// 			->setCellValue('B'.$start, 'Theo nguồn: '.$nguontin['name'])->mergeCells('B'.$start.':E'.$start);
// 		}

	
		
// 		if($ssFilter['ff_status'] != ''){
// 			$start++;
// 			if($ssFilter['ff_status'] == 0){
// 				$trangthai = 'Chưa liên hệ';
// 			}
// 			if($ssFilter['ff_status'] == 1){
// 				$trangthai = 'Đã liên hệ';
// 			}
// 			$objPHPExcel->setActiveSheetIndex(0)
// 			->setCellValue('B'.$start, 'Trạng thái: '.$trangthai)->mergeCells('B'.$start.':E'.$start);
// 		}
		
// 		if($ssFilter['keywords'] != ''){
// 			$start++;
// 			$objPHPExcel->setActiveSheetIndex(0)
// 			->setCellValue('B'.$start, 'Lọc theo từ khóa: '.$ssFilter['keywords'])->mergeCells('B'.$start.':E'.$start);
// 		}
		
// 		if($ssFilter['tungay'] != ''){
// 			$tungay = ' Từ ngày: ' . $ssFilter['tungay'];
// 		}
		
// 		if($ssFilter['denngay'] != ''){
// 			$denngay = ' Đến ngày: ' . $ssFilter['denngay'];
// 		}
		
// 		if($ssFilter['tungay'] != '' || $ssFilter['denngay'] != ''){
// 			$ngay = '';
// 			if($ssFilter['ff_ngay'] == 'ngaygui'){
// 				$ngay = 'Ngày gửi - ';
// 			}
// 			if($ssFilter['ff_ngay'] == 'ngayhen'){
// 				$ngay = 'Ngày hẹn - ';
// 			}
// 			if($ssFilter['ff_ngay'] == 'ngayhoc'){
// 				$ngay = 'Ngày học - ';
// 			}
// 			$start++;
// 			$objPHPExcel->setActiveSheetIndex(0)
// 			->setCellValue('B'.$start, 'Thời gian: '.$ngay.$tungay.$denngay)->mergeCells('B'.$start.':E'.$start);
// 		}
		/* echo "<pre>";
		print_r($this->_arrParam);
		echo "</pre>"; */
		
		// Tiêu đề
		$title = $start + 2;
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('B'.$title, 'STT');
		$objPHPExcel->getActiveSheet()->getStyle('B'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('B'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('B'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$title, 'Họ và tên');
		$objPHPExcel->getActiveSheet()->getStyle('C'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('C'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('C'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$title, 'Điện thoại');
		$objPHPExcel->getActiveSheet()->getStyle('D'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('D'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('D'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('E'.$title, 'Email');
		$objPHPExcel->getActiveSheet()->getStyle('E'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('E'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('E'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('F'.$title, 'Địa chỉ');
		$objPHPExcel->getActiveSheet()->getStyle('F'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('F'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('F'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('G'.$title, 'Tên câu lạc bộ');
		$objPHPExcel->getActiveSheet()->getStyle('G'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('G'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('G'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('H'.$title, 'Ngày hết hạn tham gia');
		$objPHPExcel->getActiveSheet()->getStyle('H'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('H'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('H'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValueExplicit('I'.$title, 'Tên lớp học');
		$objPHPExcel->getActiveSheet()->getStyle('I'.$title)->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('I'.$title)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('I'.$title)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		//Chieu cao cột title
		$objPHPExcel->getActiveSheet()->getRowDimension($title)->setRowHeight(20);
	
		// Chiều rộng cột
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(35);
		$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(25);
		//Lấy danh sach các thành viên
		if(count($listKhachhangclb) > 0){
			foreach ($listKhachhangclb AS $key => $val){
				$number = $title + $key + 1;
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('B'.$number, $key + 1);
				$objPHPExcel->getActiveSheet()->getStyle('B'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('B'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('B'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$number, $val['name']);
				$objPHPExcel->getActiveSheet()->getStyle('C'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('C'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('C'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$number, $val['phone']);
				$objPHPExcel->getActiveSheet()->getStyle('D'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('D'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('D'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('E'.$number, $val['email']);
				$objPHPExcel->getActiveSheet()->getStyle('E'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('E'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('E'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('F'.$number, $val['address']);
				$objPHPExcel->getActiveSheet()->getStyle('F'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('F'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('F'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('G'.$number, $val['name_clb']);
				$objPHPExcel->getActiveSheet()->getStyle('G'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('G'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('G'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('H'.$number, $val['ngayhethan']);
				$objPHPExcel->getActiveSheet()->getStyle('H'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('H'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('H'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				
				$objPHPExcel->getActiveSheet()->setCellValueExplicit('I'.$number, $val['ten_lophoc']);
				$objPHPExcel->getActiveSheet()->getStyle('I'.$number)->getFont();
				$objPHPExcel->getActiveSheet()->getStyle('I'.$number)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('I'.$number)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				
				
				
				
			}
		}
		
		// Rename worksheet
		//$objPHPExcel->getActiveSheet()->setTitle('Simple');
	
		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);
	
	
		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$userInfo['user_name'].'_'.@date('d_m_Y').'.xls"');
		header('Cache-Control: max-age=0');
	
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		exit;
	
	}

}



